import "font-awesome/css/font-awesome.min.css";
import "element-ui/lib/theme-default/index.css";
import babelpolyfill from "babel-polyfill";
import Vue from "vue";
import App from "./App";
import VueRouter from "vue-router";
import store from "./vuex/store";
import Vuex from "vuex";
import routes from "./routes";
import VueResource from "vue-resource";
import util from "./js/util";
import {
  Dialog,
  Menu,
  Submenu,
  MenuItem,
  Dropdown,
  DropdownMenu,
  DropdownItem,
  Input,
  Select,
  Option,
  Button,
  Table,
  TableColumn,
  DatePicker,
  Breadcrumb,
  BreadcrumbItem,
  Form,
  FormItem,
  Row,
  Col,
  MessageBox,
  Loading,
  Pagination
} from "element-ui";

Vue.use(VueRouter);
Vue.use(Vuex);
Vue.use(VueResource);
Vue.use(util);

Vue.use(Dialog);
Vue.use(Menu);
Vue.use(Submenu);
Vue.use(MenuItem);
Vue.use(Dropdown);
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Input);
Vue.use(Select);
Vue.use(Option);
Vue.use(Button);
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(DatePicker);
Vue.use(Breadcrumb);
Vue.use(BreadcrumbItem);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Row);
Vue.use(Col);
Vue.use(Loading);
Vue.use(Pagination);
//Vue.use(MessageBox);
Vue.component(MessageBox.name, MessageBox)//这样写防止自动弹出确认框

Vue.use(Loading.directive)

Vue.prototype.$loading = Loading.service;
Vue.prototype.$confirm = MessageBox.confirm;

const router = new VueRouter({
  routes
});

router.beforeEach((to, from, next) => {
  console.log("开始跳转至：" + to.path);

  if (to.path == "/login") {
    sessionStorage.removeItem("user");
  }

  let user = JSON.parse(sessionStorage.getItem("user"));
  if (!user && to.path != "/login") {
    next({ path: "/login" });
  } else {
    next();
  }
});

new Vue({
  el: "#app",
  template: "<App/>",
  router,
  store,
  components: { App }
});
